package controller

import (
	"encoding/json"
	"miao/dto"
	"miao/service"
	"strconv"

	"github.com/gin-gonic/gin"
)

func Page(c *gin.Context) {
	currentPage := c.DefaultQuery("currentPage", "1")
	pageSize := c.DefaultQuery("pageSize", "10")
	username := c.Query("username")
	intCurrentPage, _ := strconv.Atoi(currentPage)
	intPageSize, _ := strconv.Atoi(pageSize)
	result := service.PageByRole(intCurrentPage, intPageSize, username)
	c.JSON(200, result)
}

func SaveRole(c *gin.Context) {
	b, _ := c.GetRawData()
	roleDto := dto.RoleDto{}
	_ = json.Unmarshal(b, &roleDto)
	result := service.SaveRole(&roleDto)
	c.JSON(200, result)
}

func DeleteRole(c *gin.Context) {
	roleId := c.Param("roleId")
	result := service.DeleteRole(roleId)
	c.JSON(200, result)
}
